home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / sh.time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-11  |  16.0 KB  |  618 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/sh.time.c,v 3.1 1991/07/15 19:37:24 christos Exp $ */
  2. /*
  3.  * sh.time.c: Shell time keeping and printing.
  4.  */
  5. /*-
  6.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  */
  37. #include "config.h"
  38. RCSID("$Id: sh.time.c,v 3.1 1991/07/15 19:37:24 christos Exp $")
  39.  
  40. #include "sh.h"
  41. #if defined(sun) && ! defined(MACH)
  42. # include <machine/param.h>
  43. #endif                /* sun */
  44.  
  45. /*
  46.  * C Shell - routines handling process timing and niceing
  47.  */
  48. #ifdef BSDTIMES
  49. # ifndef RUSAGE_SELF
  50. #  define    RUSAGE_SELF    0
  51. #  define    RUSAGE_CHILDREN    -1
  52. # endif                /* RUSAGE_SELF */
  53. #else                /* BSDTIMES */
  54. struct tms times0;
  55.  
  56. #endif                /* BSDTIMES */
  57.  
  58. #if !defined(BSDTIMES) && !defined(_SEQUENT_)
  59. #ifdef POSIX
  60. static    void    pdtimet    __P((clock_t, clock_t));
  61. #else                /* POSIX */
  62. static    void    pdtimet    __P((time_t, time_t));
  63. #endif                /* POSIX */
  64. #else
  65. static    void    pdeltat    __P((timeval_t *, timeval_t *));
  66. #endif
  67.  
  68. void
  69. settimes()
  70. {
  71. #ifdef BSDTIMES
  72.     struct rusage ruch;
  73.  
  74.     (void) gettimeofday(&time0, NULL);
  75.     (void) getrusage(RUSAGE_SELF, &ru0);
  76.     (void) getrusage(RUSAGE_CHILDREN, &ruch);
  77.     ruadd(&ru0, &ruch);
  78. #else
  79. # ifdef _SEQUENT_
  80.     struct process_stats ruch;
  81.  
  82.     (void) get_process_stats(&time0, PS_SELF, &ru0, &ruch);
  83.     ruadd(&ru0, &ruch);
  84. # else                /* _SEQUENT_ */
  85.             time0 = times(×0);
  86.     times0.tms_stime += times0.tms_cstime;
  87.     times0.tms_utime += times0.tms_cutime;
  88.     times0.tms_cstime = 0;
  89.     times0.tms_cutime = 0;
  90. # endif                /* _SEQUENT_ */
  91. #endif                /* BSDTIMES */
  92. }
  93.  
  94. /*
  95.  * dotime is only called if it is truly a builtin function and not a
  96.  * prefix to another command
  97.  */
  98. /*ARGSUSED*/
  99. void
  100. dotime(v, c)
  101.     Char **v;
  102.     struct command *c;
  103. {
  104. #ifdef BSDTIMES
  105.     timeval_t timedol;
  106.     struct rusage ru1, ruch;
  107.  
  108.     (void) getrusage(RUSAGE_SELF, &ru1);
  109.     (void) getrusage(RUSAGE_CHILDREN, &ruch);
  110.     ruadd(&ru1, &ruch);
  111.     (void) gettimeofday(&timedol, NULL);
  112.     prusage(&ru0, &ru1, &timedol, &time0);
  113. #else
  114. # ifdef _SEQUENT_
  115.     timeval_t timedol;
  116.     struct process_stats ru1, ruch;
  117.  
  118.     (void) get_process_stats(&timedol, PS_SELF, &ru1, &ruch);
  119.     ruadd(&ru1, &ruch);
  120.     prusage(&ru0, &ru1, &timedol, &time0);
  121. # else                /* _SEQUENT_ */
  122. #  ifndef POSIX
  123.     time_t  timedol;
  124. #  else                /* POSIX */
  125.     clock_t timedol;
  126. #  endif                /* POSIX */
  127.  
  128.     struct tms times_dol;
  129.  
  130.     timedol = times(×_dol);
  131.     times_dol.tms_stime += times_dol.tms_cstime;
  132.     times_dol.tms_utime += times_dol.tms_cutime;
  133.     times_dol.tms_cstime = 0;
  134.     times_dol.tms_cutime = 0;
  135.     prusage(×0, ×_dol, timedol, time0);
  136. # endif                /* _SEQUENT_ */
  137. #endif                /* BSDTIMES */
  138. }
  139.  
  140. /*
  141.  * donice is only called when it on the line by itself or with a +- value
  142.  */
  143. /*ARGSUSED*/
  144. void
  145. donice(v, c)
  146.     register Char **v;
  147.     struct command *c;
  148. {
  149.     register Char *cp;
  150.     int     nval = 0;
  151.  
  152.     v++, cp = *v++;
  153.     if (cp == 0)
  154.     nval = 4;
  155.     else if (*v == 0 && any("+-", cp[0]))
  156.     nval = getn(cp);
  157. #ifdef BSDNICE
  158.     (void) setpriority(PRIO_PROCESS, 0, nval);
  159. #else                /* BSDNICE */
  160.     (void) nice(nval);
  161. #endif                /* BSDNICE */
  162. }
  163.  
  164. #ifdef BSDTIMES
  165. void
  166. ruadd(ru, ru2)
  167.     register struct rusage *ru, *ru2;
  168. {
  169.     tvadd(&ru->ru_utime, &ru2->ru_utime);
  170.     tvadd(&ru->ru_stime, &ru2->ru_stime);
  171. #ifndef __MINT__
  172.     if (ru2->ru_maxrss > ru->ru_maxrss)
  173.     ru->ru_maxrss = ru2->ru_maxrss;
  174.  
  175.     ru->ru_ixrss += ru2->ru_ixrss;
  176.     ru->ru_idrss += ru2->ru_idrss;
  177.     ru->ru_isrss += ru2->ru_isrss;
  178.     ru->ru_minflt += ru2->ru_minflt;
  179.     ru->ru_majflt += ru2->ru_majflt;
  180.     ru->ru_nswap += ru2->ru_nswap;
  181.     ru->ru_inblock += ru2->ru_inblock;
  182.     ru->ru_oublock += ru2->ru_oublock;
  183.     ru->ru_msgsnd += ru2->ru_msgsnd;
  184.     ru->ru_msgrcv += ru2->ru_msgrcv;
  185.     ru->ru_nsignals += ru2->ru_nsignals;
  186.     ru->ru_nvcsw += ru2->ru_nvcsw;
  187.     ru->ru_nivcsw += ru2->ru_nivcsw;
  188. #endif /* __MINT__ */
  189. }
  190.  
  191. #else                /* BSDTIMES */
  192. # ifdef _SEQUENT_
  193. void
  194. ruadd(ru, ru2)
  195.     register struct process_stats *ru, *ru2;
  196. {
  197.     tvadd(&ru->ps_utime, &ru2->ps_utime);
  198.     tvadd(&ru->ps_stime, &ru2->ps_stime);
  199.     if (ru2->ps_maxrss > ru->ps_maxrss)
  200.     ru->ps_maxrss = ru2->ps_maxrss;
  201.  
  202.     ru->ps_pagein += ru2->ps_pagein;
  203.     ru->ps_reclaim += ru2->ps_reclaim;
  204.     ru->ps_zerofill += ru2->ps_zerofill;
  205.     ru->ps_pffincr += ru2->ps_pffincr;
  206.     ru->ps_pffdecr += ru2->ps_pffdecr;
  207.     ru->ps_swap += ru2->ps_swap;
  208.     ru->ps_syscall += ru2->ps_syscall;
  209.     ru->ps_volcsw += ru2->ps_volcsw;
  210.     ru->ps_involcsw += ru2->ps_involcsw;
  211.     ru->ps_signal += ru2->ps_signal;
  212.     ru->ps_lread += ru2->ps_lread;
  213.     ru->ps_lwrite += ru2->ps_lwrite;
  214.     ru->ps_bread += ru2->ps_bread;
  215.     ru->ps_bwrite += ru2->ps_bwrite;
  216.     ru->ps_phread += ru2->ps_phread;
  217.     ru->ps_phwrite += ru2->ps_phwrite;
  218. }
  219.  
  220. # endif                /* _SEQUENT_ */
  221. #endif                /* BSDTIMES */
  222.  
  223. #ifdef BSDTIMES
  224.  
  225. /*
  226.  * PWP: the LOG1024 and pagetok stuff taken from the top command,
  227.  * written by William LeFebvre
  228.  */
  229. /* Log base 2 of 1024 is 10 (2^10 == 1024) */
  230. #define LOG1024         10
  231.  
  232. /* Convert clicks (kernel pages) to kbytes ... */
  233. /* If there is no PGSHIFT defined, assume it is 11 */
  234. /* Is this needed for compatability with some old flavor of 4.2 or 4.1? */
  235. #ifndef PGSHIFT
  236. # define pagetok(size)   ((size) << 1)
  237. #else
  238. # if PGSHIFT>10
  239. #  define pagetok(size)   ((size) << (PGSHIFT - LOG1024))
  240. # else
  241. #  define pagetok(size)   ((size) >> (LOG1024 - PGSHIFT))
  242. # endif
  243. #endif
  244.  
  245. /*
  246.  * if any other machines return wierd values in the ru_i* stuff, put
  247.  * the adjusting macro here:
  248.  */
  249. #ifdef sun
  250. # define IADJUST(i)    (pagetok(i)/2)
  251. #else                /* sun */
  252. # define IADJUST(i)    (i)
  253. #endif                /* sun */
  254.  
  255. void
  256. prusage(r0, r1, e, b)
  257.     register struct rusage *r0, *r1;
  258.     timeval_t *e, *b;
  259.  
  260. #else                /* BSDTIMES */
  261. # ifdef _SEQUENT_
  262. void
  263. prusage(r0, r1, e, b)
  264.     register struct process_stats *r0, *r1;
  265.     timeval_t *e, *b;
  266.  
  267. # else                /* _SEQUENT_ */
  268. void
  269. prusage(bs, es, e, b)
  270.     struct tms *bs, *es;
  271.  
  272. #  ifndef POSIX
  273.     time_t  e, b;
  274.  
  275. #  else                /* POSIX */
  276.     clock_t e, b;
  277.  
  278. #  endif                /* POSIX */
  279. # endif                /* _SEQUENT_ */
  280. #endif                /* BSDTIMES */
  281. {
  282. #ifdef BSDTIMES
  283.     register time_t t =
  284.     (r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
  285.     (r1->ru_utime.tv_usec - r0->ru_utime.tv_usec) / 10000 +
  286.     (r1->ru_stime.tv_sec - r0->ru_stime.tv_sec) * 100 +
  287.     (r1->ru_stime.tv_usec - r0->ru_stime.tv_usec) / 10000;
  288.  
  289. #else
  290. # ifdef _SEQUENT_
  291.     register time_t t =
  292.     (r1->ps_utime.tv_sec - r0->ps_utime.tv_sec) * 100 +
  293.     (r1->ps_utime.tv_usec - r0->ps_utime.tv_usec) / 10000 +
  294.     (r1->ps_stime.tv_sec - r0->ps_stime.tv_sec) * 100 +
  295.     (r1->ps_stime.tv_usec - r0->ps_stime.tv_usec) / 10000;
  296.  
  297. # else                /* _SEQUENT_ */
  298. #  ifndef POSIX
  299.     register time_t t = (es->tms_utime - bs->tms_utime +
  300.              es->tms_stime - bs->tms_stime) * 100 / HZ;
  301.  
  302. #  else                /* POSIX */
  303.     register clock_t t = (es->tms_utime - bs->tms_utime +
  304.               es->tms_stime - bs->tms_stime) * 100 / CLK_TCK;
  305.  
  306. #  endif                /* POSIX */
  307. # endif                /* _SEQUENT_ */
  308. #endif                /* BSDTIMES */
  309.  
  310.     register char *cp;
  311.     register long i;
  312.     register struct varent *vp = adrof(STRtime);
  313.  
  314. #ifdef BSDTIMES
  315.     int     ms =
  316.     (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;
  317.  
  318. # ifdef __MINT__
  319.     cp = "%Uu %Ss %E %P";
  320. # else
  321.     cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
  322. # endif
  323. #else
  324. # ifdef _SEQUENT_
  325.     int     ms =
  326.     (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;
  327.  
  328.     cp = "%Uu %Ss %E %P %I+%Oio %Fpf+%Ww";
  329. # else                /* _SEQUENT_ */
  330. #  ifndef POSIX
  331.     time_t  ms = (e - b) * 100 / HZ;
  332.  
  333. #  else                /* POSIX */
  334.     clock_t ms = (e - b) * 100 / CLK_TCK;
  335.  
  336. #  endif                /* POSIX */
  337.     cp = "%Uu %Ss %E %P";
  338.  
  339.     /*
  340.      * the tms stuff is not very precise, so we fudge it.
  341.      * granularity fix: can't be more than 100% 
  342.      * this breaks in multi-processor systems...
  343.      * maybe I should take it out and let people see more then 100% 
  344.      * utilizations.
  345.      */
  346.     if (ms < t && ms != 0)
  347.     ms = t;
  348. # endif                /* _SEQUENT_ */
  349. #endif                /* BSDTIMES */
  350. #ifdef TDEBUG
  351.     xprintf("es->tms_utime %lu bs->tms_utime %lu\n",
  352.         es->tms_utime, bs->tms_utime);
  353.     xprintf("es->tms_stime %lu bs->tms_stime %lu\n",
  354.         es->tms_stime, bs->tms_stime);
  355.     xprintf("ms %lu e %lu b %lu\n", ms, e, b);
  356.     xprintf("t %lu\n", t);
  357. #endif                /* TDEBUG */
  358.  
  359.     if (vp && vp->vec[0] && vp->vec[1])
  360.     cp = short2str(vp->vec[1]);
  361.     for (; *cp; cp++)
  362.     if (*cp != '%')
  363.         xputchar(*cp);
  364.     else if (cp[1])
  365.         switch (*++cp) {
  366.  
  367.         case 'U':        /* user CPU time used */
  368. #ifdef BSDTIMES
  369.         pdeltat(&r1->ru_utime, &r0->ru_utime);
  370. #else
  371. # ifdef _SEQUENT_
  372.         pdeltat(&r1->ps_utime, &r0->ps_utime);
  373. # else                /* _SEQUENT_ */
  374. #  ifndef POSIX
  375.         pdtimet(es->tms_utime, bs->tms_utime);
  376. #  else                /* POSIX */
  377.         pdtimet(es->tms_utime, bs->tms_utime);
  378. #  endif                /* POSIX */
  379. # endif                /* _SEQUENT_ */
  380. #endif                /* BSDTIMES */
  381.         break;
  382.  
  383.         case 'S':        /* system CPU time used */
  384. #ifdef BSDTIMES
  385.         pdeltat(&r1->ru_stime, &r0->ru_stime);
  386. #else
  387. # ifdef _SEQUENT_
  388.         pdeltat(&r1->ps_stime, &r0->ps_stime);
  389. # else                /* _SEQUENT_ */
  390. #  ifndef POSIX
  391.         pdtimet(es->tms_stime, bs->tms_stime);
  392. #  else                /* POSIX */
  393.         pdtimet(es->tms_stime, bs->tms_stime);
  394. #  endif                /* POSIX */
  395. # endif                /* _SEQUENT_ */
  396. #endif                /* BSDTIMES */
  397.         break;
  398.  
  399.         case 'E':        /* elapsed (wall-clock) time */
  400. #ifdef BSDTIMES
  401.         pcsecs((long) ms);
  402. #else                /* BSDTIMES */
  403.         pcsecs(ms);
  404. #endif                /* BSDTIMES */
  405.         break;
  406.  
  407.         case 'P':        /* percent time spent running */
  408.         /* check if the process did not run */
  409.         i = (ms == 0) ? 0 : (t * 1000 / ms);
  410.         xprintf("%ld.%01ld%%", i / 10, i % 10);    /* nn.n% */
  411.         break;
  412.  
  413. #if defined(BSDTIMES) && !defined(__MINT__)
  414.         case 'W':        /* number of swaps */
  415.         i = r1->ru_nswap - r0->ru_nswap;
  416.         xprintf("%ld", i);
  417.         break;
  418.  
  419.         case 'X':        /* (average) shared text size */
  420.         xprintf("%ld", t == 0 ? 0L :
  421.             IADJUST(r1->ru_ixrss - r0->ru_ixrss) / t);
  422.         break;
  423.  
  424.         case 'D':        /* (average) unshared data size */
  425.         xprintf("%ld", t == 0 ? 0L :
  426.             IADJUST(r1->ru_idrss + r1->ru_isrss -
  427.                 (r0->ru_idrss + r0->ru_isrss)) / t);
  428.         break;
  429.  
  430.         case 'K':        /* (average) total data memory used  */
  431.         xprintf("%ld", t == 0 ? 0L :
  432.             IADJUST((r1->ru_ixrss + r1->ru_isrss + r1->ru_idrss) -
  433.                (r0->ru_ixrss + r0->ru_idrss + r0->ru_isrss)) / t);
  434.         break;
  435.  
  436.         case 'M':        /* max. Resident Set Size */
  437. #ifdef sun
  438.         /* xprintf("%ld", r1->ru_maxrss * 1024L/(long) getpagesize()); */
  439.         xprintf("%ld", pagetok(r1->ru_maxrss));
  440. #else
  441.         xprintf("%ld", r1->ru_maxrss / 2L);
  442. #endif                /* sun */
  443.         break;
  444.  
  445.         case 'F':        /* page faults */
  446.         xprintf("%ld", r1->ru_majflt - r0->ru_majflt);
  447.         break;
  448.  
  449.         case 'R':        /* page reclaims */
  450.         xprintf("%ld", r1->ru_minflt - r0->ru_minflt);
  451.         break;
  452.  
  453.         case 'I':        /* FS blocks in */
  454.         xprintf("%ld", r1->ru_inblock - r0->ru_inblock);
  455.         break;
  456.  
  457.         case 'O':        /* FS blocks out */
  458.         xprintf("%ld", r1->ru_oublock - r0->ru_oublock);
  459.         break;
  460.  
  461.         case 'r':        /* PWP: socket messages recieved */
  462.         xprintf("%ld", r1->ru_msgrcv - r0->ru_msgrcv);
  463.         break;
  464.  
  465.         case 's':        /* PWP: socket messages sent */
  466.         xprintf("%ld", r1->ru_msgsnd - r0->ru_msgsnd);
  467.         break;
  468.  
  469.         case 'k':        /* PWP: number of signals recieved */
  470.         xprintf("%ld", r1->ru_nsignals - r0->ru_nsignals);
  471.         break;
  472.  
  473.         case 'w':        /* PWP: num. voluntary context switches (waits) */
  474.         xprintf("%ld", r1->ru_nvcsw - r0->ru_nvcsw);
  475.         break;
  476.  
  477.         case 'c':        /* PWP: num. involuntary context switches */
  478.         xprintf("%ld", r1->ru_nivcsw - r0->ru_nivcsw);
  479.         break;
  480. #else                /* BSDTIMES */
  481. # ifdef _SEQUENT_
  482.         case 'W':        /* number of swaps */
  483.         i = r1->ps_swap - r0->ps_swap;
  484.         xprintf("%ld", i);
  485.         break;
  486.  
  487.         case 'M':
  488.         xprintf("%ld", r1->ps_maxrss / 2);
  489.         break;
  490.  
  491.         case 'F':
  492.         xprintf("%ld", r1->ps_pagein - r0->ps_pagein);
  493.         break;
  494.  
  495.         case 'R':
  496.         xprintf("%ld", r1->ps_reclaim - r0->ps_reclaim);
  497.         break;
  498.  
  499.         case 'I':
  500.         xprintf("%ld", r1->ps_bread - r0->ps_bread);
  501.         break;
  502.  
  503.         case 'O':
  504.         xprintf("%ld", r1->ps_bwrite - r0->ps_bwrite);
  505.         break;
  506.  
  507.         case 'k':
  508.         xprintf("%ld", r1->ps_signal - r0->ps_signal);
  509.         break;
  510.  
  511.         case 'w':
  512.         xprintf("%ld", r1->ps_volcsw - r0->ps_volcsw);
  513.         break;
  514.  
  515.         case 'c':
  516.         xprintf("%ld", r1->ps_involcsw - r0->ps_involcsw);
  517.         break;
  518.  
  519.         case 'Z':
  520.         xprintf("%ld", r1->ps_zerofill - r0->ps_zerofill);
  521.         break;
  522.  
  523.         case 'i':
  524.         xprintf("%ld", r1->ps_pffincr - r0->ps_pffincr);
  525.         break;
  526.  
  527.         case 'd':
  528.         xprintf("%ld", r1->ps_pffdecr - r0->ps_pffdecr);
  529.         break;
  530.  
  531.         case 'Y':
  532.         xprintf("%ld", r1->ps_syscall - r0->ps_syscall);
  533.         break;
  534.  
  535.         case 'l':
  536.         xprintf("%ld", r1->ps_lread - r0->ps_lread);
  537.         break;
  538.  
  539.         case 'm':
  540.         xprintf("%ld", r1->ps_lwrite - r0->ps_lwrite);
  541.         break;
  542.  
  543.         case 'p':
  544.         xprintf("%ld", r1->ps_phread - r0->ps_phread);
  545.         break;
  546.  
  547.         case 'q':
  548.         xprintf("%ld", r1->ps_phwrite - r0->ps_phwrite);
  549.         break;
  550. # endif                /* _SEQUENT_ */
  551. #endif                /* BSDTIMES */
  552.         }
  553.     xputchar('\n');
  554. }
  555.  
  556. #if defined(BSDTIMES) || defined(_SEQUENT_)
  557. static void
  558. pdeltat(t1, t0)
  559.     timeval_t *t1, *t0;
  560. {
  561.     timeval_t td;
  562.  
  563.     tvsub(&td, t1, t0);
  564.     xprintf("%d.%01d", td.tv_sec, td.tv_usec / 100000);
  565. }
  566.  
  567. void
  568. tvadd(tsum, t0)
  569.     timeval_t *tsum, *t0;
  570. {
  571.  
  572.     tsum->tv_sec += t0->tv_sec;
  573.     tsum->tv_usec += t0->tv_usec;
  574.     if (tsum->tv_usec > 1000000)
  575.     tsum->tv_sec++, tsum->tv_usec -= 1000000;
  576. }
  577.  
  578. void
  579. tvsub(tdiff, t1, t0)
  580.     timeval_t *tdiff, *t1, *t0;
  581. {
  582.  
  583.     tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
  584.     tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
  585.     if (tdiff->tv_usec < 0)
  586.     tdiff->tv_sec--, tdiff->tv_usec += 1000000;
  587. }
  588.  
  589. #else                /* !BSDTIMES && !_SEQUENT_ */
  590. static void
  591. pdtimet(eval, bval)
  592. #ifndef POSIX
  593.     time_t  eval, bval;
  594.  
  595. #else                /* POSIX */
  596.     clock_t eval, bval;
  597.  
  598. #endif                /* POSIX */
  599. {
  600. #ifndef POSIX
  601.     time_t  val;
  602.  
  603. #else                /* POSIX */
  604.     clock_t val;
  605.  
  606. #endif                /* POSIX */
  607.  
  608. #ifndef POSIX
  609.     val = (eval - bval) * 100 / HZ;
  610. #else                /* POSIX */
  611.     val = (eval - bval) * 100 / CLK_TCK;
  612. #endif                /* POSIX */
  613.  
  614.     xprintf("%ld.%02ld", val / 100, val - (val / 100 * 100));
  615. }
  616.  
  617. #endif                /* BSDTIMES || _SEQUENT_ */
  618.